package org.csu.jpetstore.service.impl;

import org.csu.jpetstore.entity.Category;
import org.csu.jpetstore.mapper.CategoryMapper;
import org.csu.jpetstore.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatalogServiceImpl implements CatalogService {


    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> getCategoryList() {
        return categoryMapper.selectList(null);
    }


    @Override
    public Category getCategory(String categoryId) {
        return categoryMapper.selectById(categoryId);
    }

    @Override
    public void createNewCategory(String categoryId, String name, String image, String description) {
        Category category = new Category();
        category.setCategoryId(categoryId);
        category.setName(name);
        category.setImage(image);
        category.setDescription(description);
        categoryMapper.insert(category);
    }
}
